<template>
  <figure class="login-by-phone">
    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" size="default">
      <el-form-item prop="phone">
        <el-input
          placeholder="请输入手机号码"
          prefix-icon="el-icon-mobile-phone"
          v-model="ruleForm.phone"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item prop="verificationCode">
        <el-col :span="14">
          <el-input
            type="text"
            prefix-icon="el-icon-key"
            placeholder="请输入验证码"
            v-model="ruleForm.verificationCode"
            autocomplete="off"
            clearable
          ></el-input>
        </el-col>
        <el-col :span="10" style="text-align:right;">
          <el-button type="primary" plain>获取验证码</el-button>
        </el-col>
      </el-form-item>
      
      <el-button
        type="primary"
        size="default"
        @click="submitForm('ruleForm')"
        style="display:block;width:100%;"
      >登录</el-button>
     
    </el-form>
  </figure>
</template>

<script>
export default {
  name: "LoginByPhone",
  data() {
    return {
      ruleForm: {
        phone: "",
        verificationCode: ""
      },
      rules: {
        phone: [
          {
            required: true,
            message: "请输入手机号码",
            trigger: "blur"
          }
        ],
        verificationCode: [
          {
            required: true,
            message: "请输入验证码",
            trigger: "blur"
          }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.axios.post("/wbms/login", this.loginForm).then(res => {
            console.log(111, res);
            // if (res.data.ok === 1) {
            //   var name = res.data.data[0].name;

            //   localStorage.setItem("name", name);

            //   this.$router.push("/main");
            //   this.$message({
            //     showClose: true,
            //     message: res.data.msg,
            //     type: "success"
            //   });
            // } else {
            //   this.$message({
            //     showClose: true,
            //     message: res.data.msg,
            //     type: "error"
            //   });
            // }
          });

          // this.$message.success("登录成功");
          // setTimeout(() => {
          //   this.$router.push("/");
          // }, 1000);
        } else {
          console.log("登录失败");
          this.$message.error("登录失败");
          return false;
        }
      });
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
.login-by-phone {
  padding: 0 24px;
  width: 330px;
}
</style>
